/*!
\copyright  Copyright (c) 2020-2021 Qualcomm Technologies International, Ltd.\n
            All Rights Reserved.\n
            Qualcomm Technologies International, Ltd. Confidential and Proprietary.
\file       headset_ui_config.c
\brief      ui configuration table

    This file contains ui configuration table which maps different logical inputs to
    corresponding ui inputs based upon ui provider contexts.
*/

#include "headset_ui_config.h"
#include "ui.h"
#include "audio_curation.h"

#include "headset_buttons.h"

/* Needed for UI contexts - transitional; when table is code generated these can be anonymised
 * unsigned ints and these includes can be removed. */
#include "av.h"
#include "hfp_profile.h"
#include "bt_device.h"
#include "headset_sm.h"
#include "media_player.h"
#include "voice_ui.h"
#include "pairing.h"

#include <focus_select.h>
#include <telephony_service.h>

const focus_select_audio_tie_break_t audio_source_focus_priority[] =
{
    FOCUS_SELECT_AUDIO_LINE_IN,
    FOCUS_SELECT_AUDIO_USB,
    FOCUS_SELECT_AUDIO_A2DP
};

const focus_select_audio_tie_break_t voice_source_focus_priority[] =
{
    FOCUS_SELECT_VOICE_HFP,
    FOCUS_SELECT_VOICE_USB
};

/*! \brief ui config table*/
const ui_config_table_content_t headset_ui_config_table[] =
{
    {LI_MFB_BUTTON_QUINTUPLE_CLICK,    ui_provider_handset_pairing, context_handset_pairing_active,       ui_input_dut_mode               },
    {APP_BUTTON_CANCEL_PAIRING,        ui_provider_handset_pairing, context_handset_pairing_active,       ui_input_sm_cancel_pairing      },
    {APP_BUTTON_CANCEL_PAIRING,        ui_provider_device,          context_handset_not_connected,        ui_input_connect_handset        },

    {APP_BUTTON_MODE_SWITCH,           ui_provider_app_sm,          context_app_sm_active,                ui_input_mode_switch            },
    {APP_BUTTON_MODE_SWITCH,           ui_provider_app_sm,          context_app_sm_inactive,              ui_input_mode_switch            },

    {APP_BUTTON_POWER_ON,              ui_provider_app_sm,          context_app_sm_inactive,              ui_input_sm_power_on            },
    {APP_BUTTON_PAIR,                  ui_provider_app_sm,          context_app_sm_active,                ui_input_sm_pair_handset        },

    {APP_BUTTON_POWER_OFF,             ui_provider_app_sm,          context_app_sm_active,                ui_input_sm_power_off           },

    {APP_BUTTON_FACTORY_RESET,         ui_provider_app_sm,          context_app_sm_active,                ui_input_factory_reset_request  },

    {APP_BUTTON_VOLUME_DOWN,           ui_provider_media_player,    context_media_player_idle,            ui_input_volume_down            },
    {APP_BUTTON_VOLUME_DOWN,           ui_provider_media_player,    context_media_player_streaming,       ui_input_volume_down            },

    {APP_BUTTON_VOLUME_UP,             ui_provider_media_player,    context_media_player_idle,            ui_input_volume_up              },
    {APP_BUTTON_VOLUME_UP,             ui_provider_media_player,    context_media_player_streaming,       ui_input_volume_up              },

    {APP_BUTTON_FORWARD,               ui_provider_media_player,    context_media_player_streaming,       ui_input_av_forward             },
    {APP_BUTTON_FORWARD_HELD_RELEASE,  ui_provider_media_player,    context_media_player_streaming,       ui_input_fast_forward_stop      },
    {APP_BUTTON_BACKWARD,              ui_provider_media_player,    context_media_player_streaming,       ui_input_av_backward            },
    {APP_BUTTON_BACKWARD_HELD_RELEASE, ui_provider_media_player,    context_media_player_streaming,       ui_input_rewind_stop            },

    {APP_BUTTON_CANCEL_PAIRING,        ui_provider_media_player,    context_media_player_streaming,       ui_input_toggle_play_pause      },
    {APP_BUTTON_CANCEL_PAIRING,        ui_provider_media_player,    context_media_player_idle,            ui_input_toggle_play_pause      },

    {APP_BUTTON_GAMING_MODE_TOGGLE,    ui_provider_device,          context_handset_connected,            ui_input_gaming_mode_toggle     },

    {APP_BUTTON_BATTERY_LEVEL,         ui_provider_app_sm,          context_app_sm_active,                ui_input_sm_battery_level           },
};


const ui_config_table_content_t* HeadsetUi_GetConfigTable(unsigned* table_length)
{
    *table_length = ARRAY_DIM(headset_ui_config_table);
    return headset_ui_config_table;
}

void HeadsetUi_ConfigureFocusSelection(void)
{
    FocusSelect_ConfigureAudioSourceTieBreakOrder(audio_source_focus_priority);
    FocusSelect_ConfigureVoiceSourceTieBreakOrder(voice_source_focus_priority);
}

bool HeadsetUi_IsLogicalInputScreenedInLimboState(unsigned logical_input)
{
    switch (logical_input)
    {
    case APP_BUTTON_POWER_ON:
        return FALSE;
    default:
        return TRUE;
    }
}

bool HeadsetUi_IsLogicalInputScreenedInIdleState(unsigned logical_input)
{
    UNUSED(logical_input);

    return FALSE;
}
